package contegor.scire.core;

import java.util.Collection;

/**
 * {@link ReturnPoint} adapter.
 *
 * @version $Revision$
 * @author  Héctor Cirbián Pousa ($Author$)
 */
@Version("$Id$")
public class ReturnPointAdapter<T> implements ReturnPoint<T> {
  
  protected ReturnPointObserver observer = null;

  @Override
  public void start(TaskId taskId) {}

  @Override
  public <U extends T> void manage(TaskId taskId, U result) {}

  @Override
  public <U extends T> void manage(TaskId taskId, Collection<U> results) {
    for (T result: results)
      this.manage(taskId, result);
  }

  @Override
  public void manage(TaskId taskId, Exception exception) {
    exception.printStackTrace();
  }

  @Override
  public void finish(TaskId taskId) {
    if (this.observer != null)
      this.observer.finish(taskId);
  }

  @Override
  public void setObserver(ReturnPointObserver observer) {
    if ((this.observer != null) && (this.observer != observer))
      throw new IllegalStateException();
    this.observer = observer; 
  }
}